CC := $(CROSS_COMPILE)gcc

# 需要改为你使用的文件夹名称
# TOOLCHAIN_DIR := /home/atguigu/atguigupi

CFLAGS += -Wall -Wextra
CFLAGS += -I/home/jack/gateway
ifdef CROSS_COMPILE
CFLAGS += --sysroot=$(TOOLCHAIN_DIR)/sysroot
endif
LDFLAGS += -lpaho-mqtt3c -lcurl -lcrypto


SRCS += $(shell find app -type f -name "*.c")
SRCS += $(shell find daemon -type f -name "*.c")
SRCS += $(shell find ota -type f -name "*.c")
SRCS += $(shell find thirdparty -type f -name "*.c")

OBJS = $(SRCS:.c=.o)

TARGET = gateway

.PHONY: all clean
all : $(TARGET)

$(TARGET) : $(OBJS) main.o 
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

clean:
	$(RM) $(OBJS) main.o $(TARGET)

test_buffer : $(OBJS) test/test_buffer.o 
	-@$(CC) $(CFLAGS) -o $@ $^
	-@./$@
	-@$(RM) $@ $^

test_mqtt : $(OBJS) test/test_mqtt.o
	-@$(CC) $(CFLAGS) -o $@ $^ -Ithirdparty -lpaho-mqtt3c
	-@./$@
	-@$(RM) $@ $^

test_message: $(OBJS) test/test_message.o
	-@$(CC) $(CFLAGS) -o $@ $^ -Ithirdparty -lpaho-mqtt3c
	-@./$@
	-@$(RM) $@ $^
	
test_task: $(OBJS) test/test_task.o
	-@$(CC) $(CFLAGS) -o $@ $^ -Ithirdparty -lpaho-mqtt3c
	-@./$@
	-@$(RM) $@ $^	